<%@ tag import="j.framework.core.FApplication" %>
<%@ tag import="j.util.StringUtils" %>
<%@ tag body-content="scriptless" pageEncoding="utf-8" %>
<%@ taglib prefix="j" uri="j/tags" %>

<%--
    action与requestId必须指定其中一个，若指定了requestId，则action的值将忽略
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ attribute name="formId" required="true" rtexprvalue="true" %>
<%@ attribute name="action" required="false" rtexprvalue="true" %>
<%@ attribute name="requestId" required="false" rtexprvalue="true" %>
<%
    String base = FApplication.getResourceUrl("/");
    request.setAttribute("base",base);
    //request.setAttribute("base","http://localhost:4900/resource/");
    if(StringUtils.isNotEmpty(requestId)){
        action = "/user/req";
        request.setAttribute("action",action);
    }
%>
<!DOCTYPE html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
    <title>对话框</title>
    <link rel="stylesheet" type="text/css" href="${base}widgets/easyui/themes/default/easyui.css?0.1" />
    <link rel="stylesheet" type="text/css" href="${base}widgets/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${base}styles/common.css" />
    <script type="text/javascript" src="${base}js/jquery.min.js"></script>
    <style>
        body{overflow: hidden;}
    </style>
</head>
<body>
<script>
    var _dialogArguments;
    var _parent;
    if(typeof window.showModalDialog === "function"){
        //这是用模态窗口打开的
        _dialogArguments = window.dialogArguments;
        _parent = _dialogArguments.parent;
    }else{
        _dialogArguments = window.data;
        _parent = window.opener;
    }
</script>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="doSave();">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-back'" onclick="window.close();">返回</a>
    </div>
    <div data-options="region:'center',border:true">
        <form id="${formId}" action="${action}" method="post" target="post_form">
            <input type="hidden" name="HTTP_POST_BY_FORM" value="1"/>
            <input type="hidden" name="action" value="save"/>
            <c:if test="${not empty requestId}">
                <input type="hidden" name="rid" value="<j:des data="${requestId}"/>"/>
            </c:if>
            <jsp:doBody/>
        </form>
    </div>
</div>
    <iframe width="0" scrolling="no" height="0" frameborder="0" name="post_form" src="/none.html" style="display:none;"></iframe>
<script type="text/javascript" src="${base}js/public.js?0.5"></script>
<script type="text/javascript" src="${base}js/http.js?0.1"></script>
<script type="text/javascript" src="${base}widgets/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${base}widgets/easyui/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${base}js/jquery-html5Validate.js?v0.1"></script>
<script>
    function doOk(){
        alert("保存成功！");
        var frm = document.getElementById("${formId}");
        if(typeof doAfterSave === "function"){
            doAfterSave(null,_dialogArguments);
        }else{
            try {
                _parent.reload();
            }catch(e){}
        }
        window.close();
    }
    function doSave(){
        var frm = document.getElementById("${formId}");
        if(typeof doBeforeSave === "function"){
            var ret = doBeforeSave(frm,_dialogArguments);
            if(!ret){
                return false;
            }
        }
        if ($.html5Validate.isAllpass($(frm))) {
            $(frm).submit();
        }
        //alert('ok');

    }
    var f = {};
    f.setError = function(errMsg){
        alert(errMsg);
    };
    f.close = function(){
        doOk();
    };
    $(function(){
        if(_dialogArguments){
            var title = _dialogArguments.title;
            if(typeof title == "string" && title!=""){
                window.document.title = title;
            }
        }
    });
</script>
</body>
</html>


